
function success(result, request) {
	var myObject = eval('(' + result.responseText + ')');
	var torrents = myObject['arguments']['torrents'];
	var torrentsParsed = new Array();
	for (var i=0; i < torrents.length; i++) {
		torrentsParsed[i] = new Array(torrents[i]['name']);				
	}
		
	Ext.getCmp("torrents").getStore().loadData(torrentsParsed);
}

function failure(result, request) {
	Ext.MessageBox.alert('Failed', 'Successfully posted form: '+result.date); 
}


function doAjax() {
	Ext.Ajax.request({
			url : 'Transmission.php' , 
			params : {foo:'bar'},
			method: 'GET',
			success: success,
			failure: failure
		});

}

function updateData() {
    doAjax();
    
    
  

}

Ext.onReady(function(){
 
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

	
    // create the data store
    var store = new Ext.data.ArrayStore({
        fields: [
           {name: 'name'}
           /*{name: 'size'},
           {name: 'done'},
           {name: 'status'},
		   {name: 'seeds'},
		   {name: 'peers'},
		   {name: 'downspeed'},
		   {name: 'upspeed'},
           {name: 'eta', type: 'date', dateFormat: 'h'}*/
        ]
    });
    //store.loadData(myData);
    /*var testData = '{"torrents":[{"id": 10,"name": "Fedora x86_64 DVD","totalSize": 3333}]}';
    var store = new Ext.data.JsonStore({
    // store configs
    	autoDestroy: true,

		root: 'torrents',
    // reader configs
    	fields: ['id', 'name', 'totalSize']
    });
    store.loadData(testData);*/
	var viewport = new Ext.Viewport({
		layout: 'border',
		items: [
			new Ext.Panel({
				region:'north',
				height:30
				
			}
				
			),
			new Ext.ux.StatusBar({
				region: 'south',
				xtype:'tbsplit',
				height:25,
				items: [
					{text:'D: 143.4 kB/s T:694.8MB'}, '-', {text:'U: 38.4 kB/s T:318.4MB'}
				]
				
				
			})
			
			,
			new Ext.grid.GridPanel({
				region: 'center',
				id: 'torrents',
				store: store,
				/*columns: [
					{id:'name',header: "Name", width: 160, sortable: true, dataIndex: 'name'},
					{header: "Size", width: 75, sortable: true, dataIndex: 'size'},
					{header: "Done", width: 75, dataIndex: 'done'},
					{header: "Status", width: 75, dataIndex: 'status'},
					{header: "Seeds", width: 75, dataIndex: 'seeds'},
					{header: "Peers", width: 75, dataIndex: 'peers'},
					{header: "Down speed", width: 75, dataIndex: 'downspeed'},
					{header: "Up speed", width: 75, dataIndex: 'upspeed'},
					{header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
				],*/
				columns: [
					{id:'name',header: "Name", width: 160, sortable: true, dataIndex: 'name'}
					//{header: "Total size", width: 75, sortable: true, dataIndex: 'totalSize'}
					
				],
				stripeRows: true,
				autoExpandColumn: 'name'
			
				
			})]
		});
    setInterval("updateData()", 2000);
});